package site.xuxingcan.autodownload;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Administrator on 2016/9/24.
 */
public class WidActivity extends AppCompatActivity {
    private Handler mHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mHandler = new Handler(Looper.myLooper());
        setContentView(R.layout.activity_wid);
        TextView wid = (TextView) findViewById(R.id.wid);
        String widString = WID.getImeiMd5(MyApplication.mContext);
        if (widString.equalsIgnoreCase("4076b89bd3ff86eac73d786e232a5646")) {
            wid.setText("获取IMEI失败，请检查设备权限！");
        } else {
            wid.setText(widString);
            wid.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    android.content.ClipboardManager c = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                    c.setText(WID.getImeiMd5(MyApplication.mContext));
                    Toast.makeText(WidActivity.this, "机器码已经复制", Toast.LENGTH_SHORT).show();
                }
            });
            new Thread(new Runnable() {
                @Override
                public void run() {
                    if (AuthUtil.Auth()) {
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                startActivity(new Intent(WidActivity.this, MainActivity.class));
                                finish();
                            }
                        });
                    } else {
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(WidActivity.this, "验证失败！", Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                }
            }).start();
        }
    }
}
